home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / addstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  8.5 KB  |  294 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. /* undefine any macros for functions defined in this module */
  23. #undef    addstr
  24. #undef    addnstr
  25. #undef    waddstr
  26. #undef    waddnstr
  27. #undef    mvaddstr
  28. #undef    mvaddnstr
  29. #undef    mvwaddstr
  30. #undef    mvwaddnstr
  31.  
  32. /* undefine any macros for functions called by this module if in debug mode */
  33. #ifdef PDCDEBUG
  34. #  undef    move
  35. #  undef    wmove
  36. #  undef    addch
  37. #  undef    waddch
  38. #endif
  39.  
  40. #ifdef PDCDEBUG
  41. char *rcsid_addstr  = "$Id$";
  42. #endif
  43.  
  44. /*man-start*********************************************************************
  45.  
  46.   Name:                                                        addstr
  47.  
  48.   Synopsis:
  49.       int addstr(char *str);
  50.       int addnstr(char *str, int n);
  51.       int waddstr(WINDOW *win, char *str);
  52.       int waddnstr(WINDOW *win, char *str, int n);
  53.       int mvaddstr(int y, int x, char *str);
  54.       int mvaddnstr(int y, int x, char *str, int n);
  55.       int mvwaddstr(WINDOW *, int y, int x, char *str);
  56.       int mvwaddnstr(WINDOW *, int y, int x, char *str, int n);
  57.  
  58.   X/Open Description:
  59.      These routines write all the characters of the null-terminated
  60.      string str on the given window.  The functionality is equivalent
  61.      to calling waddch() once for each character in the string.  The four
  62.      routines with n as the last argument write at most n characters.  If n
  63.      is negative, then the entire string will be added.
  64.  
  65.      NOTE:    addstr(), mvaddstr(), and mvwaddstr() are implemented as macros.
  66.          addnstr(), mvaddnstr(), and mvwaddnstr() are implemented as macros.
  67.  
  68.   PDCurses Description:
  69.      The *raw*() routines output 8 bit values.  These contrast to their
  70.      normal counterparts which output 7 bit values and convert control
  71.      character to the ^X notation.
  72.  
  73.      str is a standard 8 bit character string WITHOUT embedded attributes.
  74.  
  75.   X/Open Return Value:
  76.      All functions return OK on success and ERR on error.
  77.  
  78.   X/Open Errors:
  79.      No errors are defined for this function.
  80.  
  81.   Portability                             X/Open    BSD    SYS V
  82.                                           Dec '88
  83.       addstr                                Y        Y       Y
  84.       waddstr                               Y        Y       Y
  85.       mvaddstr                              Y        Y       Y
  86.       mvwaddstr                             Y        Y       Y
  87.       addnstr                               -        -      4.0
  88.       waddnstr                              -        -      4.0
  89.       mvaddnstr                             -        -      4.0
  90.       mvwaddnstr                            -        -      4.0
  91.  
  92. **man-end**********************************************************************/
  93.  
  94. /***********************************************************************/
  95. int    addstr(char *str)
  96. /***********************************************************************/
  97. {
  98.     int i;
  99. #ifdef PDCDEBUG
  100.     if (trace_on) PDC_debug("addstr() - called: string=\"%s\"\n",str);
  101. #endif
  102.  
  103.     if (stdscr == (WINDOW *)NULL)
  104.         return( ERR );
  105.  
  106.     while (*str)
  107.     {
  108.         if ((i = *str++)<0) i += 256;  /* make negative chars positive - PJK */
  109.         if (PDC_chadd( stdscr, (chtype)i, (bool)(!(_cursvar.raw_out)), TRUE ) == ERR)
  110.         {
  111.             return( ERR );
  112.         }
  113.     }
  114.     return( OK );
  115. }
  116. /***********************************************************************/
  117. int    addnstr(char *str, int n)
  118. /***********************************************************************/
  119. {
  120.     int ic = 0;
  121.     int i;
  122. #ifdef PDCDEBUG
  123.     if (trace_on) PDC_debug("addnstr() - called: string=\"%s\" n %d \n",str,n);
  124. #endif
  125.  
  126.     if (stdscr == (WINDOW *)NULL)
  127.         return( ERR );
  128.  
  129.     while ( *str && (ic < n || n < 0) )
  130.     {
  131.         if ((i = *str++)<0) i += 256;  /* make negative chars positive - PJK */
  132.         if (PDC_chadd( stdscr, (chtype)i, (bool)(!(_cursvar.raw_out)), TRUE ) == ERR)
  133.         {
  134.             return( ERR );
  135.         }
  136.         ic++;
  137.     }
  138.     return( OK );
  139. }
  140. /***********************************************************************/
  141. int    waddstr(WINDOW *win, char *str)
  142. /***********************************************************************/
  143. {
  144.     int i;
  145. #ifdef PDCDEBUG
  146.     if (trace_on) PDC_debug("waddstr() - called: string=\"%s\"\n",str);
  147. #endif
  148.  
  149.     if (win == (WINDOW *)NULL)
  150.         return( ERR );
  151.  
  152.     while (*str)
  153.     {
  154.         if ((i = *str++)<0) i += 256;  /* make negative chars positive - PJK */
  155.         if (PDC_chadd( win, (chtype)i, (bool)(!(_cursvar.raw_out)), TRUE ) == ERR)
  156.         {
  157.             return( ERR );
  158.         }
  159.     }
  160.     return( OK );
  161. }
  162. /***********************************************************************/
  163. int    waddnstr(WINDOW *win, char *str, int n)
  164. /***********************************************************************/
  165. {
  166.     int ic = 0;
  167.     int i;
  168.  
  169. #ifdef PDCDEBUG
  170.     if (trace_on) PDC_debug("waddnstr() - called: string=\"%s\" n %d \n",str,n);
  171. #endif
  172.  
  173.     if (win == (WINDOW *)NULL)
  174.         return( ERR );
  175.  
  176.     while ( *str && (ic < n || n < 0) )
  177.     {
  178.         if ((i = *str++)<0) i += 256;  /* make negative chars positive - PJK */
  179.         if (PDC_chadd( win, (chtype)i, (bool)(!(_cursvar.raw_out)), TRUE ) == ERR)
  180.         {
  181.             return( ERR );
  182.         }
  183.         ic++;
  184.     }
  185.     return( OK );
  186. }
  187. /***********************************************************************/
  188. int    mvaddstr(int y, int x, char *str)
  189. /***********************************************************************/
  190. {
  191.     int i;
  192. #ifdef PDCDEBUG
  193.     if (trace_on) PDC_debug("mvaddstr() - called: y %d x %d string=\"%s\"\n",y,x,str);
  194. #endif
  195.  
  196.     if (stdscr == (WINDOW *)NULL)
  197.         return( ERR );
  198.  
  199.     if (wmove(stdscr,y,x) == ERR)
  200.         return( ERR );
  201.  
  202.     while (*str)
  203.     {     
  204.         if ((i = *str++)<0) i += 256;  /* make negative chars positive - PJK */
  205.         if (PDC_chadd( stdscr, (chtype)i, (bool)(!(_cursvar.raw_out)), TRUE ) == ERR)
  206.         {
  207.             return( ERR );
  208.         }
  209.     }
  210.     return( OK );
  211. }
  212. /***********************************************************************/
  213. int    mvaddnstr(int y, int x, char *str, int n)
  214. /***********************************************************************/
  215. {
  216.     int ic = 0;
  217.     int i;
  218.  
  219. #ifdef PDCDEBUG
  220.     if (trace_on) PDC_debug("mvaddnstr() - called: y %d x %d string=\"%s\" n %d \n",y,x,str,n);
  221. #endif
  222.  
  223.     if (stdscr == (WINDOW *)NULL)
  224.         return( ERR );
  225.  
  226.     if (wmove(stdscr,y,x) == ERR)
  227.         return( ERR );
  228.  
  229.     while ( *str && (ic < n || n < 0) )
  230.     {                
  231.         if ((i = *str++)<0) i += 256;  /* make negative chars positive - PJK */
  232.         if (PDC_chadd( stdscr, (chtype)i, (bool)(!(_cursvar.raw_out)), TRUE ) == ERR)
  233.         {
  234.             return( ERR );
  235.         }
  236.         ic++;
  237.     }
  238.     return( OK );
  239. }
  240. /***********************************************************************/
  241. int    mvwaddstr(WINDOW *win, int y, int x, char *str)
  242. /***********************************************************************/
  243. {
  244.     int i;
  245. #ifdef PDCDEBUG
  246.     if (trace_on) PDC_debug("waddstr() - called: string=\"%s\"\n",str);
  247. #endif
  248.  
  249.     if (win == (WINDOW *)NULL)
  250.         return( ERR );
  251.  
  252.     if (wmove(win,y,x) == ERR)
  253.         return( ERR );
  254.  
  255.     while (*str)
  256.     {     
  257.         if ((i = *str++)<0) i += 256;  /* make negative chars positive - PJK */
  258.         if (PDC_chadd( win, (chtype)i, (bool)(!(_cursvar.raw_out)), TRUE ) == ERR)
  259.         {
  260.             return( ERR );
  261.         }
  262.     }
  263.     return( OK );
  264. }
  265. /***********************************************************************/
  266. int    mvwaddnstr(WINDOW *win,int y, int x, char *str, int n)
  267. /***********************************************************************/
  268. {
  269.     int ic = 0;
  270.     int i;
  271.  
  272. #ifdef PDCDEBUG
  273.     if (trace_on) PDC_debug("mvwaddnstr() - called: y %d x %d string=\"%s\" n %d \n",y,x,str,n);
  274. #endif
  275.  
  276.     if (win == (WINDOW *)NULL)
  277.         return( ERR );
  278.  
  279.     if (wmove(win,y,x) == ERR)
  280.         return( ERR );
  281.  
  282.     while ( *str && (ic < n || n < 0) )
  283.     {     
  284.         if ((i = *str++)<0) i += 256;  /* make negative chars positive - PJK */
  285.         if (PDC_chadd( win, (chtype)i, (bool)(!(_cursvar.raw_out)), TRUE ) == ERR)
  286.         {
  287.             return( ERR );
  288.         }
  289.         ic++;
  290.     }
  291.     return( OK );
  292. }
  293.